package cn.tedu.hongpei.controller;

import cn.tedu.hongpei.Exception.BusinessException;
import cn.tedu.hongpei.mapper.UserMapper;
import cn.tedu.hongpei.pojo.Dto.UserRegDto;
import cn.tedu.hongpei.pojo.Dto.UserUpdateDTO;
import cn.tedu.hongpei.pojo.User;
import cn.tedu.hongpei.response.AppCode;
import cn.tedu.hongpei.response.ResultVo;
import cn.tedu.hongpei.util.FileUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import java.util.Date;
import java.util.List;

/**
 * @author coinyang
 * @date 2023/3/21 10:47
 */
@Slf4j
@RestController
@RequestMapping("user")
@Api(tags = "用户管理")
public class UserController {
    @Autowired
    UserMapper userMapper;


    @ApiOperation("查询用户列表")
    @GetMapping(value = "selectAll")
    public ResultVo selectAll(){
        log.debug("开始查询所有的用户信息");
        List<User> list  =userMapper.selectAll();
        return ResultVo.success(list) ;
    }

    @ApiOperation("用户注册")
    @PostMapping("reg")
    public ResultVo reg(  @Validated UserRegDto userRegDto){
        log.debug("开始注册用户信息"+userRegDto);
        User user = new User();
        BeanUtils.copyProperties(userRegDto,user);
        Date d = new Date();
        user.setCreateTime(d);
        log.debug("user数据---------"+user);
        userMapper.insert(user);
        return ResultVo.success() ;
    }


    @ApiOperation("用户更新")
    @PostMapping(value = "update")
    public ResultVo updateByPrimaryKey(UserUpdateDTO user){
        log.debug("开始查询所有的用户信息");
        userMapper.updateByPrimaryKey(user);
        return ResultVo.success() ;
    }


}
